//
//  starView.m
//  Movie
//
//  Created by tengyang on 15/7/21.
//  Copyright (c) 2015年 tengyang. All rights reserved.
//

#import "starView.h"

@implementation starView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self _createSubViews];
    }
    return self;
}


//UIImage *image1=[UIImage imageNamed:@"yellow"];
//UIImage *image2=[UIImage imageNamed:@"gray"];
//UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(0, 8, image1.size.width*_modal.average*0.5, image1.size.height)];
//
//UIView *view2=[[UIView alloc]initWithFrame:CGRectMake(0, 8, image2.size.width*5, image2.size.height)];
//view1.backgroundColor=[UIColor colorWithPatternImage:image1];
//view2.backgroundColor=[UIColor colorWithPatternImage:image2];
//[_starView addSubview:view2];
//[_starView addSubview:view1];


- (void)_createSubViews
{
    UIImage *grayImage=[UIImage imageNamed:@"gray"];
    UIImage *yelowImage=[UIImage imageNamed:@"yellow"];
    _grayView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, grayImage.size.width*5, grayImage.size.height)];
    _yellowView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, yelowImage.size.width*5, yelowImage.size.height)];
    _grayView.backgroundColor=[UIColor colorWithPatternImage:grayImage];
    _yellowView.backgroundColor=[UIColor colorWithPatternImage:yelowImage];
    [self addSubview:_grayView];
    [self addSubview:_yellowView];
    
    
    float scaleHeight=self.frame.size.height/grayImage.size.height;
    //float scaleWidth=self.frame.size.width/grayImage.size.width;
    _grayView.transform=CGAffineTransformMakeScale(scaleHeight, scaleHeight);
    _yellowView.transform=CGAffineTransformMakeScale(scaleHeight, scaleHeight);
    
    
    CGRect frame=_yellowView.frame;
    CGPoint point=CGPointZero;
    frame.origin=point;
    _yellowView.frame=frame;
    _grayView.frame=frame;
    
    
    
    
}

- (void)setAverage:(float)average
{
    _average=average;
    [self setNeedsLayout];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    float width=_average/10.0*_yellowView.frame.size.width;
    CGRect frame=_grayView.frame;
    frame.size.width=width;
    _yellowView.frame=frame;
    
}


@end
